package com.joker.controller;

import com.joker.bean.Weather;
import com.joker.util.WeatherUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

@Controller
public class WeatherController {

    @RequestMapping(value = "/getWeatherToWEIXIN")
    public void getWeather(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=utf-8");
        /*设置响应头允许ajax跨域访问*/
        response.setHeader("Access-Control-Allow-Origin", "*");

        /* 星号表示所有的异域请求都可以接受， */
        response.setHeader("Access-Control-Allow-Methods", "GET,POST");

        String city = WeatherUtil.getCity();
        System.out.println(city);
        PrintWriter out = response.getWriter();
        out.write(city);
    }
}
